package com.lanyun.auth.controller.admin.authRolePermission;


import com.google.common.base.Preconditions;
import com.lanyun.auth.controller.admin.authRolePermission.vo.AuthRolePermissionRequestVO;
import com.lanyun.auth.domain.authRolePermission.AuthRolePermissionDomainService;
import com.lanyun.web.bean.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 角色权限controller
 *
 * @Author Jqcc
 * @Version 1.0
 * @Data 2025/3/12
 */
@RestController
@RequestMapping("/api-admin/rolePermission/")
@Slf4j
public class AuthRolePermissionController {

    @Resource
    private AuthRolePermissionDomainService authRolePermissionDomainService;

    /**
     * 新增角色权限关联关系
     *
     * @param authRolePermissionRequestVO
     * @return
     */
    @PostMapping("add")
    public Result<Boolean> add(@RequestBody AuthRolePermissionRequestVO authRolePermissionRequestVO) {
        try {

            Preconditions.checkNotNull(authRolePermissionRequestVO.getRoleId(), "角色不能为空");
            Preconditions.checkArgument(!CollectionUtils.isEmpty(authRolePermissionRequestVO.getPermissionIdList()), "权限关联不能为空");

            return Result.success(authRolePermissionDomainService.add(authRolePermissionRequestVO));
        } catch (IllegalArgumentException e) {
            log.error("AuthRolePermissionDTO.add.error:{}", e.getMessage(), e);
            return Result.fail(e.getMessage());
        }
    }
}
